Skip to main content

Interview CheatSheet

Here’s a cheatsheet for technical interview preparation with code snippets in JavaScript:

1. Clear Communication

// Organize thoughts before speaking
console.log("Let's first define the input and expected output.");

2. Request More Examples

// Ask for more examples or edge cases
console.log("Can you provide an example with an edge case, like an empty array?");

3. Discuss Time & Space Complexity

// Discuss time complexity
console.log("This solution has a time complexity of O(n log n) because we sort the array.");

4. Validate with Test Cases

// Run test cases after coding
const input = [1, 2, 3];
const output = myFunction(input);
console.assert(output === expectedOutput, `Test failed: ${output}`);

5. Handle Ambiguity in Outputs

// Clarify if multiple solutions are acceptable
console.log("Should I return one solution, or multiple possible answers?");

6. Align on Input Format

// Clarify input format
console.log("Just to confirm, the input graph will be an adjacency list?");

7. Improve Code Readability

// Add whitespace for clarity
function add(a, b) {
let result = a + b; // Adds a and b
return result;
}

8. Add Small Annotations

// Add comments for clarity
// Check if the array is empty
if (!arr.length) return [];

9. Use Type Annotations

// Type annotations for clarity
/**
* Adds two numbers
* @param {number} a
* @param {number} b
* @returns {number}
*/
function add(a, b) {
return a + b;
}